<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Approves extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'approves';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text',
        'type_text',
    ];

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3') ];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    

    
    public function getStatusList()
    {
        return ['cancel' => __('Status cancel'), 'wait' => __('Status wait'), 'ing' => __('Status ing'), 'pass' => __('Status pass'), 'refuse' => __('Status refuse')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    //申请人
    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id');
    }


    //请假内容
    public function leave()
    {
        return $this->belongsTo('app\admin\model\ApprovesLeave', 'id', 'approves_id');
    }

    //报销内容
    public function reimburse()
    {
        return $this->belongsTo('app\admin\model\ApprovesReimburse', 'id', 'approves_id');
    }

    //采购内容
    public function purchase()
    {
        return $this->belongsTo('app\admin\model\ApprovesPurchase', 'id', 'approves_id');
    }

}
